package org.dromara.crawler.mongo.mongoservice.impl;

import cn.hutool.core.util.ObjectUtil;
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
import com.mongoplus.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.dromara.crawler.domain.bo.DataCollectionBo;
import org.dromara.crawler.mongo.mongodomain.CNN;
import org.dromara.crawler.mongo.mongoservice.CNNService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CNNServiceImpl extends ServiceImpl<CNN> implements CNNService {

    @Override
    public List<CNN> queryCNNByLabel(String label) {
        return this.lambdaQuery().eq(CNN::getLabel,label).list();
    }

    @Override
    public LambdaQueryChainWrapper createWrapper(DataCollectionBo dataCollectionBo) {
        LambdaQueryChainWrapper<CNN> wrapper = this.lambdaQuery();
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getEventFirstLevel()),CNN::getEventFirstLevel, dataCollectionBo.getEventFirstLevel());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getEventSecondLevel()),CNN::getEventSecondLevel, dataCollectionBo.getEventSecondLevel());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getKeyword()), CNN::getKeyword, dataCollectionBo.getKeyword());
        wrapper.gte(ObjectUtil.isNotEmpty(dataCollectionBo.getStartTime()),CNN::getTime,dataCollectionBo.getStartTime());
        wrapper.lte(ObjectUtil.isNotEmpty(dataCollectionBo.getEndTime()),CNN::getTime,dataCollectionBo.getEndTime());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getTitle()), CNN::getTitle, dataCollectionBo.getTitle());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getStatus1()), CNN::getStatus1, dataCollectionBo.getStatus1());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getStatus2()), CNN::getStatus2, dataCollectionBo.getStatus2());
        wrapper.orderByDesc(CNN::getCrawlTime);
        return wrapper;
    }

    @Override
    public CNN queryById(String id) {
        return this.getById(id);

    }
}
